// pages/View/View.js
var order = ['red', 'yellow', 'blue', 'green', 'red']
var initData = 'this is firstline\nthis is second line'
var extraLine = []
var types = ['default', 'primary', 'warn']
const date = new Date()
const years = []
const months = []
const days = []
for (let i=1990;i<date.getFullYear();i++){
  years.push(i)
}
for(let i=1;i<=12;i++){
  months.push(i)
}
for(let i=1;i<=31;i++){
  days.push(i)
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    toView: 'red',
    scrollTop: 100,
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 1000,
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    x:0,
    y:0,
    iconSize:[20, 30, 40, 50, 60, 70],
    iconType: [
      'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear'
    ],
    iconColor: [
      'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'
    ],
    text: initData,
    nodes:[
      {
      name: 'div',
      attrs: {
        class:'relative',
        style:'line-height;color:red;'
      },
      children:[{
        type:'text',
        text:'Hello&nbsp;World!'
      }],
      
    }
    ],
    defaultSize: 'default',
    primarySize: 'default',
    buttonTypes: ['primary', "default",'warn','primary'],
    warnSize: 'default',
    disabled: false,
    plain: false,
    loading: false,
    items: [
      { name: 'USA', value: '美国' },
      { name: 'CHN', value: '中国', checked: 'true' },
      { name: 'BRA', value: '巴西' },
      { name: 'JPN', value: '日本' },
      { name: 'ENG', value: '英国' },
      { name: 'TUR', value: '法国' },
    ],
    confirmTypes:['send', 'search', 'next', 'go', 'done'],
    arr:['红','黄','蓝'],
    index:0,
    multiArray: [['无脊柱动物', '脊柱动物'], ['扁性动物', '线形动物', '环节动物', '软体动物', '节肢动物'], ['猪肉绦虫', '吸血虫']],
    multiIndex: [0, 0, 0],
    time:"15:00",
    date:"2018-5-6",
    field:'day',
    region: ['广东省', '广州市', '海珠区'],
    years:years,
    year:date.getFullYear(),
    months:months,
    month:2,
    days:days,
    day:2,
    value:[9999,1,1]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.videoCtx = wx.createVideoContext('myVideo')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  upper:function(e){
    console.log(e)
  },
  lower:function(e){
    console.log(e)
  },
  scroll:function(e){
    console.log(e)
  },
  tap: function (e) {
    for (var i = 0; i < order.length; ++i) {
      if (order[i] === this.data.toView) {
        this.setData({
          toView: order[i + 1]
        })
        break
      }
    }
  },
  tapMove: function (e) {
    this.setData({
      scrollTop: this.data.scrollTop + 10
    })
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    console.log(e)
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  swiperChange:function(e){
    console.log(e)
  },
  tapMoveRight:function(){
    var a = this.data.x+30
    console.log(a)
    this.setData({
      x:a
    })
  },
  tapMoveBottom:function(){
    var a = this.data.y+30
    this.setData({
      y:a
    })
  },
  play() {
    this.videoCtx.play()
  },
  pause() {
    this.videoCtx.pause()
  },
  add:function(){
    extraLine.push('other   line')
    this.setData({
      text:initData+'\n'+extraLine.join('\n')
    })
  },
  remove:function(){
    if(extraLine.length>0){
      extraLine.pop()
      this.setData({
        text:initData+'\n'+extraLine.join('\n')
      })
    }
  },
  changeButtonSize:function(){
    if (this.data.defaultSize == 'default'){
      this.setData({
        defaultSize:'mini'
      })
    }else{
      this.setData({
        defaultSize: 'default'
      })
    }
  },
  chageButtonType:function(){
    for(var i=0;i<this.data.buttonTypes.length;++i){
      if (this.data.primarySize == this.data.buttonTypes[i]){
        this.setData({
          primarySize: this.data.buttonTypes[i+1]
        })
        break
      }
    }
  },
  changeButtonType:function(){
    if (this.data.plain){
      this.setData({
        plain:false
      })
    }else{
      this.setData({
        plain: true
      })
    }
  },
  changeButtonDisable:function(){
    this.setData({
      disabled:this.data.disabled?false:true
    })
  },
  changeButtonLoading:function(){
    this.setData({
      loading: this.data.loading ? false : true
    })
  },
  bindgetuserinfo: function(e){
    console.log(e)
  },
  checkboxChange: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
  },
  formSubmit:function(e){
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
  },
  formReset:function(){
    console.log('form发生了reset事件')
  },
  inputEnter:function(e){
    console.log(e)
  },
  inputFocus:function(e){
    console.log(e)
  },
  inputBlur:function(e){
    console.log(e)
  },
  inputFirm:function(e){
    console.log(e)
  },
  bindPickerChange:function(e){
    console.log(e)
    this.setData({
      index: e.detail.value
    })
  },
  multiBindChange:function(e){
    console.log(e)
    this.setData({
      multiIndex:e.detail.value
    })
  },
  multiBindColumnChange(e){
    console.log(e)
  },
  timeBindChange:function(e){
    console.log(e.detail)
    this.setData({
      time:e.detail.value
    })
  },
  dateBindChange:function(e){
    console.log(e)
    this.setData({
      date:e.detail.value
    })
  },
  changeDateField: function () {
    let fields = ['year', 'month', 'day', 'year']
    for (var i = 0; i < fields.length; i++) {
        if(this.data.field == fields[i]){
          this.setData({
            field:fields[i+1]
          })
          break
        }
    }
  },
  chageBindRegion:function(e){
    console.log(e)
    this.setData({
      region:e.detail.value
    })
  },
  pickerViewChange:function(e){
    const val = e.detail.value
    console.log(val)
  },
  radioBindChange:function(e){
    console.log(e)
  },
  sliderBindChange:function(e){
    console.log('滑动完成   '+e)
  },
  sliderBindChanging:function(e){
    console.log('滑动中    '+e)
  },
  switchBindChange:function(e){
    console.log(e.detail.value)
  },
  areaBindFocue:function(e){
    console.log(e.detail)
  },
  areaBindBlur:function(e){
    console.log(e.detail)
  },
  areaBindLineChange:function(e){
    console.log(e.detail)
  },
  areaBindInput:function(e){
    console.log(e.detail)
  },
  areaBindConfirm:function(e){
    console.log(e.detail)
  }
})